
package com.bt.dmdb.controller.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.bt.dmdb.controller.UsersController;
import com.bt.dmdb.model.CustomerDetails;
import com.bt.dmdb.model.CustomerDocument;
import com.bt.dmdb.model.LoginUser;
import com.bt.dmdb.model.Question;
import com.bt.dmdb.service.UsersService;

@Controller
@RequestMapping("users")
public class UsersControllerImpl implements UsersController {

    @Resource
    private UsersService usersService;

    public UsersService getUsersService() {
        return usersService;
    }

    public void setUsersService(UsersService usersService) {
        this.usersService = usersService;
    }
    
    @Override
    @RequestMapping(value = "getLoggedInUser", method = RequestMethod.GET)
    @ResponseBody
    public LoginUser getLoggedInUser(HttpSession session) {
        Long userId = null;
        if (!session.isNew()) {
        	LoginUser user = (LoginUser) session.getAttribute("user");
            if(user != null)
            userId = user.getId();
        }
        return usersService.getLoggedInUser(userId);
    }
    
    @Override
    @RequestMapping(value = "findAllUsers", method = RequestMethod.GET)
    @ResponseBody
    public List<LoginUser> findAllUsers() {
    	 return usersService.findAllUsers();
    }
    
    @Override
    @RequestMapping(value = "findUserById", method = RequestMethod.GET)
    @ResponseBody
    public LoginUser findUserById(@RequestParam long id) {
    	 return usersService.findUserById(id);
    }
    
    @Override
    @RequestMapping(value = "findCustomerById", method = RequestMethod.GET)
    @ResponseBody
    public CustomerDetails findCustomerById(@RequestParam long id) {
    	 return usersService.findCustomerById(id);
    }
    
    @Override
    @RequestMapping(value = "deleteUserById", method = RequestMethod.GET)
    //@ResponseBody
    public ModelAndView deleteUserById(@RequestParam long id) {
    	  usersService.deleteUserById(id);
    	  return new ModelAndView("newTables");
    	  
    }
    
    @Override
    @RequestMapping(value = "findDocumentByCustId", method = RequestMethod.GET)
    @ResponseBody
    public List<CustomerDocument> findDocumentByCustId(@RequestParam long id) {
    	 return usersService.findDocumentByCustId(id);
    }
    
    @Override
    @RequestMapping(value = "findNFFECommonQuestion", method = RequestMethod.GET)
    @ResponseBody
    public List<Question> findNFFECommonQuestion() {
    	 return usersService.findNFFECommonQuestion();
    }
    
    @Override
    @RequestMapping(value = "findMakerInitialQuestion", method = RequestMethod.GET)
    @ResponseBody
    public Map<Object, Object> findMakerInitialQuestion() {
    	 return usersService.findMakerInitialQuestion();
    }
    
    @Override
    @RequestMapping(value = "getListOfNFFECategory", method = RequestMethod.GET)
    @ResponseBody
    public List<Object> getListOfNFFECategory() {
    	 return usersService.getListOfNFFECategory();
    }
	
    
    @Override
    @RequestMapping(value = "getListOfFFICategory", method = RequestMethod.GET)
    @ResponseBody
    public List<Object> getListOfFFICategory() {
    	 return usersService.getListOfFFICategory();
    }
    
}
